/**	
 * <br>
 * Copyright 2012 Chuan. All rights reserved.<br>
 * <br>			 
 * Package: com.chuan.mantu <br>
 * FileName: PicActivity.java <br>
 * <br>
 * @version
 * @author javacyc@qq.com
 * @created 2012-11-15
 * @last Modified 
 * @history
 */

package com.chuan.mantu;

import android.app.ActivityGroup;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.chuan.mantu.utils.Const;
import com.chuan.mantu.utils.MoveBg;

/**
 * {图片浏览界面}
 *  
 *  @author javacyc@qq.com
 *  @created 2012-11-15 下午03:45:50
 *  @lastModified       
 *  @history           
 */

public class PicActivity extends ActivityGroup {

	RelativeLayout layout;
	RelativeLayout layout_pic_main;
	LayoutInflater inflater;
	Intent intent;
	View page;//用来存放顶部具体分类的view
	TextView tv_front;//需要移动的View
	TextView tv_bar_yinhun;
	TextView tv_bar_jingdian;
	TextView tv_bar_gaoxiao;
	TextView tv_bar_gangman;
	TextView tv_bar_mairou;
	TextView tv_bar_qita;
	
	int avg_width = 0;// 用于记录平均每个标签的宽度，移动的时候需要
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pic);
	
		
		layout = (RelativeLayout) findViewById(R.id.layout_title_bar);
		layout_pic_main = (RelativeLayout) findViewById(R.id.layout_pic_main);
		inflater = getLayoutInflater();
		
		tv_bar_yinhun = (TextView) findViewById(R.id.tv_title_bar_yinhun);
		tv_bar_jingdian = (TextView) findViewById(R.id.tv_title_bar_jingdian);
		tv_bar_gaoxiao = (TextView) findViewById(R.id.tv_title_bar_gaoxiao);
		tv_bar_gangman = (TextView) findViewById(R.id.tv_title_bar_gangman);
		tv_bar_mairou = (TextView) findViewById(R.id.tv_title_bar_mairou);
		tv_bar_qita = (TextView) findViewById(R.id.tv_title_bar_qita);

		tv_bar_yinhun.setOnClickListener(onClickListener);
		tv_bar_jingdian.setOnClickListener(onClickListener);
		tv_bar_gaoxiao.setOnClickListener(onClickListener);
		tv_bar_gangman.setOnClickListener(onClickListener);
		tv_bar_mairou.setOnClickListener(onClickListener);
		tv_bar_qita.setOnClickListener(onClickListener);

		tv_front = new TextView(this);
		tv_front.setBackgroundResource(R.drawable.slidebar);
		tv_front.setTextColor(Color.WHITE);
		tv_front.setText(getString(R.string.title_pic_category_yinhun));
		tv_front.setGravity(Gravity.CENTER);
		RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		param.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		layout.addView(tv_front, param);
		
		//默认显示“银魂”
		intent = new Intent(PicActivity.this, PicShowActivity.class);
		intent.putExtra(Const.PIC_CATEGORY, Const.PIC_CATEGORY_YINHUN);
		page = getLocalActivityManager().startActivity("activity1", intent).getDecorView();
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		layout_pic_main.addView(page, params);
		
	}

	private OnClickListener onClickListener = new OnClickListener() {
		int startX;//移动的起始位置
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		@Override
		public void onClick(View v) {
			Const.IF_BITMAP_RECYCLE = true;
			getLocalActivityManager().removeAllActivities();
			avg_width = findViewById(R.id.layout).getWidth();
			switch (v.getId()) {
			case R.id.tv_title_bar_yinhun:
				MoveBg.moveFrontBg(tv_front, startX, 0, 0, 0);
				startX = 0;
				tv_front.setText(R.string.title_pic_category_yinhun);
				//准备显示“银魂”
				page = inflater.inflate(R.layout.picshow, null);
				intent.setClass(PicActivity.this, PicShowActivity.class);
				intent.putExtra(Const.PIC_CATEGORY, Const.PIC_CATEGORY_YINHUN);
				page = getLocalActivityManager().startActivity("activity1", intent).getDecorView();
				break;
			case R.id.tv_title_bar_jingdian:
				MoveBg.moveFrontBg(tv_front, startX, avg_width, 0, 0);
				startX = avg_width;
				tv_front.setText(R.string.title_pic_category_jingdian);
				//准备显示“经典”
				intent.setClass(PicActivity.this, PicShowActivity.class);
				intent.putExtra(Const.PIC_CATEGORY, Const.PIC_CATEGORY_JINGDIAN);
				page = getLocalActivityManager().startActivity("activity2", intent).getDecorView();
				break;
			case R.id.tv_title_bar_gaoxiao:
				MoveBg.moveFrontBg(tv_front, startX, avg_width * 2, 0, 0);
				startX = avg_width * 2;
				tv_front.setText(R.string.title_pic_category_gaoxiao);
				//准备显示“搞笑”
				intent.setClass(PicActivity.this, PicShowActivity.class);
				intent.putExtra(Const.PIC_CATEGORY, Const.PIC_CATEGORY_GAOXIAO);
				page = getLocalActivityManager().startActivity("activity3", intent).getDecorView();
				break;
			case R.id.tv_title_bar_gangman:
				MoveBg.moveFrontBg(tv_front, startX, avg_width * 3, 0, 0);
				startX = avg_width * 3;
				tv_front.setText(R.string.title_pic_category_gangman);
				//准备显示“港漫”
				intent.setClass(PicActivity.this, PicShowActivity.class);
				intent.putExtra(Const.PIC_CATEGORY, Const.PIC_CATEGORY_GANGMAN);
				page = getLocalActivityManager().startActivity("activity4", intent).getDecorView();
				break;
			case R.id.tv_title_bar_mairou:
				MoveBg.moveFrontBg(tv_front, startX, avg_width * 4, 0, 0);
				startX = avg_width * 4;
				tv_front.setText(R.string.title_pic_category_mairou);
				//准备显示“卖肉”
				intent.setClass(PicActivity.this, PicShowActivity.class);
				intent.putExtra(Const.PIC_CATEGORY, Const.PIC_CATEGORY_MAIROU);
				page = getLocalActivityManager().startActivity("activity5", intent).getDecorView();
				break;
			case R.id.tv_title_bar_qita:
				MoveBg.moveFrontBg(tv_front, startX, avg_width * 5, 0, 0);
				startX = avg_width * 5;
				tv_front.setText(R.string.title_pic_category_qita);
				//准备显示“其他”
				intent.setClass(PicActivity.this, PicShowActivity.class);
				intent.putExtra(Const.PIC_CATEGORY, Const.PIC_CATEGORY_QITA);
				page = getLocalActivityManager().startActivity("activity6", intent).getDecorView();
				break;

			default:
				break;
			}
			//切换
			layout_pic_main.removeAllViews();
			layout_pic_main.addView(page, params);
		}
	};
	
}